package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0077.java
 * @Author : WangRuoyu
 * @Date 2023/11/1 16:55
 */


public class Q0077 {
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> tmp = new ArrayList<>();
    int n;
    int k;
    boolean[] st;

    private void dfs(int x) {
        if (tmp.size() == k) {
            res.add(new ArrayList<>(tmp));
            return;
        }
        for (int i = x; i <= n; i++) {
            if (n - x + 1 < k - tmp.size()) {
                return;
            }
            st[i] = true;
            tmp.add(i);
            dfs(i + 1);
            st[i] = false;
            tmp.remove(tmp.size() - 1);
        }
    }

    public List<List<Integer>> combine(int n, int k) {
        this.n = n;
        this.k = k;
        st = new boolean[n + 1];
        dfs(1);
        return res;
    }

    public static void main(String[] args) {
        Q0077 sl = new Q0077();
        System.out.println(sl.combine(4, 2));
    }
}